import pagination from '@/views/pagination'  //分页组件
import agentHttp from '@/utils/agentHttp.js'//引用JS
import {debounce,setEndDateTime} from '@/utils/index.js'
export default {
  name: 'accountsReceivable',//组件名称
  components:{pagination},
  created(){//初始化
    this.seachData();
    this.getSum();
    this.allButton = buttonPermission('all');
    this.addButton= buttonPermission('add');
    this.updateButton= buttonPermission('update');
  },
  data() {//初始化数据
  	return {
      orderNumber:"",
      orderNumberSum:"",
      date:"",
      dateSum:"",
  	  //弹窗状态数据
      dialogSendData:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      //表格字段
      tableData:{	         
      },
      //搜索字段
  		searchForm:{	  			
	        startDate:"",
	        endDate:"",
	        orderNumber:""
  		},
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now() 
        }
      },
      endDateOpt:{
        disabledDate:(time)=>{
          return  time.getTime()< new Date(this.searchForm.startDate).getTime();
        }
      },
      resetFormStatus:false
  	}
  },
  methods: {//所有方法
    //重算当前订单服务费
    countOrderNumber(){
      if(this.orderNumber==""){
        this.$message.warning("请先输入需重算的订单号！");
        return;
      }
      agentHttp.postJson('adminApi/admin/order_charges_detail/recalculate_interest_by_order_number',this.orderNumber ).then((data)=>{
        if (data.success) {
          this.$message.success(data.data||"重新计算成功");
          this.seachData();
          this.getSum();  
        }
      })
    },
    //重算此日期所有订单的服务费
    countDate(){
      if(this.date==""){
        this.$message.warning("请先选择需重算的日期！");
        return;
      }
      agentHttp.postJson('adminApi/admin/order_charges_detail/recalculate_interest_by_date',this.date ).then((data)=>{
        if (data.success) {
          this.$message.success(data.data||"重新计算成功");
          this.seachData();
          this.getSum();
        }
      })
    },
    //列表查询
    seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        params.endDate = setEndDateTime(params.endDate);
        agentHttp.postJson('adminApi/admin/order_charges_detail/queryAllByEntity?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
          this.tableData = data
        })
      }
    },
    //总计查询
    getSum(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.endDate = setEndDateTime(params.endDate);
        agentHttp.postJson('adminApi/admin/order_charges_detail/get_sum',params ).then((data)=>{
          if (data.success) {
            this.orderNumberSum = data.data.newInterest;
            this.dateSum = data.data.exceed;
          }
        })
      }
    },
    //延迟搜索
    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(),1000);
      debounce(this.getSum(),1000);
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
        this.getSum();
      })
    }   
  }
}